<template>
	<view class="wrapper">
		<view class="top-box">
			<view class="wrap">
				<view class="fl-class flex bg-ff" style="justify-content: space-around;">
					<view class="icon " v-for="(item,index) in categorOption" :key="index">
						<image mode="widthFix" :src="item.img"></image>
						<view>{{ item.name }}</view>
					</view>
				</view>
				<!-- 搜索框 -->
				<view class="input-box">
					<input class="s-txt" type="text" v-model="searchText" placeholder="帖子搜索" />
					<view class="icon search" @click="Tosearch">
						<image src="https://web.suqzp.com/public/search.png"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="notcel bg-ff">
			<view class="wrap">
				<view class="hptel-th flex">
					<image src="https://web.suqzp.com/public/jiud.png" class="jdimg"></image>
					<view class="fs-28 fc-33 w-534">广州市-希尔顿酒店发布一个新活动,可获得88员优惠广州市-希尔顿酒店发布一个新活动,可获得88员优惠</view>
				</view>
			</view>
		</view>
		<view class="nav-tab flex bg-ff">
			<view v-for="(item, index) in navList" :key="index" class="nav-item"
				:class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">
				{{ item.text }}
			</view>
		</view>
		<!-- 显示区域 -->
		<view class="list" v-for="(item, index) in navList" :key="index" v-if="tabCurrentIndex === index">
			<view class="bg-ff mar-bot-16 list-wap" v-for="(item,index) in modelData" @click="goToDesc(item)">
				<view class="list-item">
					<view class="flex l-1">
						<view class="im1s">
							<image :src="item.avatar">
							</image>
						</view>
						<view class="fc-33 fs-28">{{item.nickname}}</view>
						<image v-if="item.is_member == 'Y'" src="https://web.suqzp.com/public/icon/vip.png" class="vipimg"></image>
					</view>
					<view class="two-ellipsis fs-28 fc-33 lin-h-20 pad-top-10">
						<text class="s-att fc-66">{{ item.categoryName }}</text>
						{{ item.title }}
					</view>
					<!-- 部落富文本展示内容 暂时隐藏 -->
					<!-- <view class="contents fc-66 fs-26">
						公司发布的内容公司发布的内容公司发布的内容公司发布的内容公司发布的内容，公司发布的内容公司发布的内容公司发布的内容公司发布的内容公司发布的内，容公司发布的内容公司发布的内。
					</view>
					<view class="report-img flex mar-top-20">
						<view class="img-style" v-for="(item,index) in img">
							<image :src="item.src"></image>
						</view>
					</view> -->
					<view class="flex jcsb">
						<view class="fs-26 fc-99">
							<view class="lok-icon">
								<image src="https://web.suqzp.com/public/look.png"></image>
							</view>
							{{ item.readCount }}
						</view>
						<view class="fs-26 fc-99">
							<view class="lok-icon">
								<image src="https://web.suqzp.com/public/zf.png"></image>
							</view>
							{{ item.shareCount }}
						</view>
						<view class="fs-26 fc-99">
							<view class="lok-icon">
								<image src="https://web.suqzp.com/public/zan.png"></image>
							</view>
							{{ item.likeCount }}
						</view>
						<view class="fs-26 fc-99">
							<view class="lok-icon">
								<image src="https://web.suqzp.com/public/info.png"></image>
							</view>
							{{ item.commentCount }}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="release-but" @click="Torelease">
			<image src="https://web.suqzp.com/public/add.png"></image>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				categorOption: '', // 帖子分类
				modelData: '', // 帖子列表
				searchText: '', // 搜索标题
				searchForm: {}, // 查询条件
				// 分类菜单
				categoryList: [{
						id: 1,
						name: '社会百态',
						img: this.$mConfig.imgSrcUrl + 's1-icon.png'
					},
					{
						id: 2,
						name: '生活百科',
						img: this.$mConfig.imgSrcUrl + 's2-icon.png'
					},
					{
						id: 3,
						name: '人文科技',
						img: this.$mConfig.imgSrcUrl + 's3-icon.png'
					},
					{
						id: 4,
						name: '文史地理',
						img: this.$mConfig.imgSrcUrl + 's4-icon.png'
					},
					{
						id: 1,
						name: '社会百态',
						img: this.$mConfig.imgSrcUrl + 's1-icon.png'
					},
					{
						id: 2,
						name: '生活百科',
						img: this.$mConfig.imgSrcUrl + 's2-icon.png'
					},
					{
						id: 3,
						name: '人文科技',
						img: this.$mConfig.imgSrcUrl + 's3-icon.png'
					},
					{
						id: 4,
						name: '文史地理',
						img: this.$mConfig.imgSrcUrl + 's4-icon.png'
					}
				],
				navList: [{
						state: 0,
						text: '综合',
						orderList: []
					},
					{
						state: 1,
						text: '推荐',
						orderList: []
					},
					{
						state: 2,
						text: '最新',
						orderList: []
					},
					{
						state: 3,
						text: '最多浏览',
						orderList: []
					},
					{
						state: 4,
						text: '最多评论',
						orderList: []
					}
				],
				tabCurrentIndex: 0,
				img: [{
					src: 'https://web.suqzp.com/public/static/q.jpg'
				}, {
					src: 'https://i-7xvfsljtcgf3cswfwvr8oss.oss-cn-shenzhen.aliyuncs.com/sqzp/common/xkACpnRtDx.jpg'
				}, {
					src: 'https://web.suqzp.com/public/static/q.jpg'
				}],
			};
		},
		onLoad() {
			// 页面显示是默认选中第一个
			this.tabCurrentIndex = 0;
		},
		async mounted() {
			await this.getCategory()
			await this.getTribeList()
		},
		computed: {

		},
		methods: {
			// 获取帖子类别
			getCategory() {
				this.$apis.getTribeCategoryList().then(res => {
					res.rows.forEach((item,index) => {
						item.img = this.$mConfig.imgSrcUrl + `s${index % 4 + 1}-icon.png`
					})
					this.categorOption = res.rows
				})
			},
			// 获取所有帖子
			getTribeList() {
				this.$apis.getTribePostsList(this.searchForm).then(res => {
					// 数据处理 解析帖子类型
					res.rows.forEach(item => {
						item.categoryName = this.getLabelByValue(item.categoryId)
					})
					this.modelData = res.rows
					console.log('this.modelData ', this.modelData)
				})
			},
			// 跳转到查看详情页面
			goToDesc(item) {
				console.log('item',item)
				// 携带Id跳转到查看详情页面
				uni.navigateTo({
					url: `../user/person/busines/posts-show?id=${item.id}`
				})
			},
			//顶部tab点击
			tabClick(index) {
				console.log(index)
				this.tabCurrentIndex = index;
				this.searchForm = this.$options.data().searchForm;
				// 根据选中查询条件 查询
				if (index == 0) {
					// 综合查询
					this.getTribeList()
				} else if (index == 1) {
					// 推荐查询
					this.searchForm.isRecommend = 1
					this.getTribeList()
				} else if (index == 2) {
					// 最新排序
					this.searchForm.orderField = 'create_time'
					this.searchForm.orderType = 'desc'
					this.getTribeList()
				} else if (index == 3) {
					// 最多浏览排序
					this.searchForm.orderField = 'read_count'
					this.searchForm.orderType = 'desc'
					this.getTribeList()
				} else if (index == 4) {
					// 最多评论排序
					this.searchForm.orderField = 'comment_count'
					this.searchForm.orderType = 'desc'
					this.getTribeList()
				}
			},
			// 帖子搜索
			Tosearch() {
				this.searchForm.title = this.searchText
				this.getTribeList()
			},
			// 跳转到发布页面
			Torelease() {
				uni.navigateTo({
					url: '/pages/house_tribe/tribe/tribe_posts'
				})
			},
			// 帖子类型转换
			getLabelByValue(value) {
				if (!value) return 'wuwuwu';
				let result = this.categorOption.find(item => {
					return item.id == value;
				})
				console.log(result)
				return result.name || '无';
			}
		}
	}
</script>
<style lang="scss">
	.wrapper {
		background: #f8f8f8;
		padding-bottom: 100rpx;

		.top-box {
			background: linear-gradient(180deg, #84C0F4 0%, #FFFFFF 100%);

			.fl-class {
				width: 100%;
				height: auto;
				display: flex;
				justify-content: flex-start;
				padding: 30rpx 0 18rpx;
				flex-flow: wrap;
				background: #FFFFFF;
				box-shadow: 0px 3px 6px 1px rgba(0, 0, 0, 0.050980392156862744);
				border-radius: 14rpx;

				.icon {
					width: 25%;
					display: flex;
					flex-flow: wrap;
					justify-content: center;
					font-size: 22upx;
					color: #666;
					margin-bottom: 20rpx;

					image {
						width: 80rpx;
						height: 80rpx;
					}
				}
			}

			.input-box {
				width: 100%;
				height: 80rpx;
				background-color: #F7F9F9;
				position: relative;
				display: flex;
				align-items: center;
				flex: 1;
				border-radius: 100rpx;
				margin-top: 14rpx;
				position: relative;
				top: 35rpx;

				.s-txt {
					font-size: 28rpx;
					color: #999;
					width: 100%;
				}

				.icon {
					display: flex;
					align-items: center;
					position: absolute;
					top: 28rpx;
					left: 32rpx;

					image {
						width: 30rpx;
						height: 30rpx;
						display: inline-block;
						display: flex;
						align-items: center;
					}
				}

				input {
					padding-left: 72rpx;
					height: 28rpx;
					font-size: 28rpx;
				}
			}
		}

		.notcel {
			margin-bottom: 12rpx;

			.wrap {
				padding: 0 4% 0;

				.hptel-th {
					height: 60px;
					margin: 6px 0;
					background: #fff;

					.jdimg {
						width: 82rpx;
						height: 76rpx;
						display: block;
						position: relative;
						top: 20rpx;
					}

					.w-534 {
						height: 66rpx;
						width: 534rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						position: relative;
						top: 24rpx;
						left: 20rpx;
						padding-left: 20rpx;
						border-left: 1px solid #eee;
					}
				}
			}
		}

		.nav-tab {
			height: 88rpx;
			line-height: 88rpx;

			.nav-item {
				flex: 1;
				display: flex;
				justify-content: center;
				align-items: center;
				height: 100%;
				font-size: 30rpx;
				color: $font-color-dark;
				position: relative;

				&.current {
					color: #323232;

					&:after {
						content: '';
						position: absolute;
						left: 50%;
						bottom: 0;
						transform: translateX(-50%);
						width: 48rpx;
						height: 0;
						border-bottom: 2px solid #89C3F5;
					}
				}
			}
		}

		.list {
			background: #f8f8f8;
			padding-bottom: 100rpx;

			.list-wap {
				padding: 20rpx 0;
			}

			.list-item {
				padding: 0 4%;

				.s-att {
					width: 160rpx;
					height: 52rpx;
					background: rgba(253, 101, 83, 0.10196078431372549);
					line-height: 52rpx;
					text-align: center;
					display: inline-block;
					margin-right: 16rpx;
				}

				.vipimg {
					width: 64rpx;
					height: 32rpx;
					display: block;
					margin-left: 16rpx;
				}
			}

			.mar-bot-16 {
				margin-bottom: 16rpx;
			}

			.lin-h-20 {
				line-height: 42rpx;
			}

			.l-1 {
				margin: 18rpx 0;

				.im1s {
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
					display: block;
					margin-right: 20rpx;

					image {
						width: 40rpx;
						height: 40rpx;
						border-radius: 50%;
					}
				}
			}

			.report-img {
				.img-style {
					margin: 0 0 24rpx 12rpx;
					width: 220rpx;
					height: 210rpx;
					border-radius: 8rpx;
					display: flex;
					align-items: center;
					overflow: hidden;

					image {
						width: 100%;
					}
				}

				.img-style:nth-child(3n+1) {
					margin: 0 0rpx 24rpx 0;
				}
			}

			.lok-icon {
				width: 44rpx;
				height: 44rpx;
				display: inline-block;
				margin-right: 6rpx;
				position: relative;
				top: 10rpx;

				image {
					width: 44rpx;
					height: 44rpx;
					display: block;
				}
			}
		}
	}

	.release-but {
		width: 156rpx;
		height: 156rpx;
		display: block;
		position: fixed;
		bottom: 20%;
		right: 0;

		image {
			width: 156rpx;
			height: 156rpx;
			display: block;
		}
	}
</style>
